#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    //ages[x]>=ages[y]>ages[x]*0.5+7
    //>14
    int numFriendRequests(vector<int>& ages) {
        int left = 0, right = 0, n = ages.size();
        int res = 0;
        sort(ages.begin(), ages.end());
        for (auto age : ages)
        {
            if (age < 15) continue;
            while (ages[left] <= age * 0.5 + 7) ++left;
            while (right + 1 < n && ages[right + 1] <= age) ++right;
            res += right - left;
        }

        return res;
    }
};